use super::Rect;

pub struct Anchor {
    pub x_min: f32,
    pub x_max: f32,
    pub y_min: f32,
    pub y_max: f32,
}

pub struct Measure {
    pub anchor: Anchor,
    pub padding: Rect,
}

impl Default for Measure {
    fn default() -> Self {
        Self {
            anchor: Anchor {
                x_min: 0.0,
                x_max: 1.0,
                y_min: 0.0,
                y_max: 1.0,
            },
            padding: Rect {
                left: 0.0,
                right: 0.0,
                bottom: 0.0,
                top: 0.0,
            },
        }
    }
}

impl Measure {
    pub fn measure_rect(&self, parent: &Rect) -> Rect {
        let left = parent.left + parent.width() * self.anchor.x_min + self.padding.left;
        let right = parent.left + parent.width() * self.anchor.x_max - self.padding.right;
        let bottom = parent.bottom + parent.height() * self.anchor.y_min + self.padding.bottom;
        let top = parent.bottom + parent.height() * self.anchor.y_max - self.padding.top;

        Rect {
            left,
            right,
            bottom,
            top,
        }
    }
}
